package com.atguigu.eduservice.controller;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.impl.EduVideoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cyt
 * @create 2020-05-09 14:07
 */
@Api(description = "小结管理")

@RequestMapping("/eduservice/video")
@RestController
public class EduVideoController {

    @Autowired
    EduVideoService eduVideoService;

    // 添加
    @PostMapping("/saveVideo")
    public R saveVideo(@RequestBody EduVideo eduVideo) {

        System.out.println(eduVideo);
        eduVideoService.save(eduVideo);
        return R.ok();
    }

    // 删除, 把阿里云中的视频也删除掉
    @DeleteMapping("/deleteVideo/{id}")
    public R deleteVideo(@PathVariable String id) {
        boolean videoById = eduVideoService.removeVideoById(id);
        if (videoById) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    // 更新

    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.updateById(eduVideo);
        return R.ok();
    }

    // 查找
    @GetMapping("/getVideo/{id}")
    public R getVideo(@PathVariable String id) {
        EduVideo videoServiceById = eduVideoService.getById(id);
        return R.ok().data("video", videoServiceById);
    }
}
